package game;


//This class define a set of allowed char for a sequence
public class Set {
	private char set[];
	private int dim;
	private int head;

	//Simple constructor, char must be added then
	public Set(int dim){
		this.set = new char[dim];
		this.dim = dim;
		head = 0;
	}
	
	//Constructor that already grab a set of char
	public Set(char set[]){
		this.set = set;		
		this.dim = set.length;
		head = dim - 1;
		int i = 0;
		char temp;
		while(i <= head){
			if(check(this.set[i])){
				temp = this.set[i];
				this.set[i] = this.set[head];
				this.set[head] = temp;
				head = head - 1;
			}
		}
		
	}
	
	public int getDim(){
		return dim;
	}
	
	//Subroutine in order to add a char to set, no duplicate are allowed, and / is reserved
	public boolean addChar(char c){
		if(head == dim-1 || check(c) || c == '/'){
			return false;			
		}
		else{
			this.set[head] = c;
			head++;
			return true;
		}
	}
	
	//Subroutine in order to remove a char to set
	public boolean removeChar(){
		if (head == 0){
			return false;
		}
		else{
			head--;
			return true;
		}
	}
	
	//This check if a char is already in set
	public boolean check(char c){
		boolean b = false;
		int i = 0;
		while (!b && i <= head){
			if(c == set[i]) b = true;
			i++;
		}
		return b;
	}
	
	public char[] getSet(){
		return set;
	}
}
